package qc.module.ehs.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.ehs.dto.accidentrecord.AccidentRecordDto;
import qc.module.ehs.dto.accidentrecord.AccidentRecordQueryConditionDto;
import qc.module.ehs.service.EhsAccidentRecordService;

import java.util.List;

/**
 * AccidentRecordController
 * 
 * @author QuCheng Tech
 * @since 2024/10/29
 */
@RestController
@RequestMapping("/accidentrecord")
public class AccidentRecordController {
    
    @Autowired
    private EhsAccidentRecordService service;

    /**
     * 查询记录
     * 
     * @param condition 查询条件
     * @return List<AccidentRecordDto>
     * @author QuCheng Tech
     * @since 2024/10/30
     */ 
    @RequestMapping(value = "/query",method = {RequestMethod.GET,RequestMethod.POST})
    public List<AccidentRecordDto> query(@RequestBody AccidentRecordQueryConditionDto condition) throws QCPromptException {
        return service.query(condition);
    }

    /**
     * 获取指定
     * 
     * @param id 事故记录ID
     * @return AccidentRecordDto
     * @author QuCheng Tech
     * @since 2024/10/30
     */
    @GetMapping("/get")
    public AccidentRecordDto getByParam(@RequestParam String id){
        return service.get(id);
    }

    /**
     * 获取指定
     *
     * @param id 事故记录ID
     * @return AccidentRecordDto
     * @author QuCheng Tech
     * @since 2024/10/30
     */
    @GetMapping("/get/{id}")
    public AccidentRecordDto getByPath(@PathVariable String id){
        return service.get(id);
    }

    /**
     * 新增
     * 
     * @param dto 
     * @return 成功返回null，失败返回错误或提示信息
     * @author QuCheng Tech
     * @since 2024/10/30
     */
    @RequestMapping(value = "/add",method = {RequestMethod.POST})
    public String add(@RequestBody AccidentRecordDto dto) throws QCPromptException {
        return service.add(dto);
    }

    /**
     * 修改
     *
     * @param dto
     * @return 成功返回null，失败返回错误或提示信息
     * @author QuCheng Tech
     * @since 2024/10/30
     */
    @RequestMapping(value = "/update",method = {RequestMethod.POST,RequestMethod.PUT})
    public String update(@RequestBody AccidentRecordDto dto) throws QCPromptException {
        return service.update(dto);
    }

    /**
     * 删除
     * 
     * @param id 事故记录ID
     * @return 成功返回null，失败返回错误或提示信息
     * @author QuCheng Tech
     * @since 2024/10/30
     */
    @DeleteMapping("/delete")
    public String deleteByParam(@RequestParam String id){
        return service.delete(id);
    }

    /**
     * 删除
     *
     * @param id 事故记录ID
     * @return 成功返回null，失败返回错误或提示信息
     * @author QuCheng Tech
     * @since 2024/10/30
     */
    @DeleteMapping("/delete/{id}")
    public String deleteByPath(@PathVariable String id){
        return service.delete(id);
    }
}
